package com.younion.action.manage;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.younion.common.base.BaseAction;
import com.younion.common.paginator.Paginator;

import cpcns.jhsks.util.MapCollectionUtils;

import com.younion.business.IMobileMessageService;
import com.younion.vo.MobileMessageVO;

/**
 * @author wells
*/
public class MobileMessageAction extends BaseAction {

	private static final long serialVersionUID = 1L;

	protected static final Log logger = LogFactory.getLog(MobileMessageAction.class);

	private IMobileMessageService mobileMessageService = null;

	private MobileMessageVO mobileMessageVO = new MobileMessageVO();

	private List<MobileMessageVO> mobileMessageList;// 结果集列表
	/**
	 * 列表：翻页区；数据区
	 */
	@SuppressWarnings("unchecked")
	public String listMobileMessage() {
		try {
			Map paramMap = null;
			if (mobileMessageVO != null) {
				paramMap = MapCollectionUtils.removeEmptyEntry(PropertyUtils.describe(mobileMessageVO));
			}
			// 获取总记录数
			int total = mobileMessageService.getCountByMap(paramMap);
			// 根据总记录数获取分页对象
			Paginator paginator = this.getPaginator(total);
			mobileMessageList = mobileMessageService.get(paramMap, paginator);
			// 保存分页对象
			this.savaPaginator(paginator);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
		}
		return SUCCESS;
	}

	/**
	 * 新增
	 */
	public String addMobileMessage() {
		return SUCCESS;
	}

	/**
	 * 修改保存，调度Jsp
	 */
	public String editMobileMessage() {
		try {
			mobileMessageVO = mobileMessageService.getById(mobileMessageVO.getId().toString());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}

	/**
	 * 保存动作
	 */
	public String saveMobileMessage() {
		try {
			mobileMessageVO = mobileMessageService.save(mobileMessageVO);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			e.printStackTrace();
		}
		return SUCCESS;
	}

	/**
	 * 删除
	 */
	public String deleteMobileMessage() {
		try {
			String pkId = request.getParameter("key");
			mobileMessageService.remove(Arrays.asList(pkId.split(",")));
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			e.printStackTrace();
		}
		return SUCCESS;
	}
	/**
	 * 查看鿴
	 */
	public String viewMobileMessage() {
		try {
			String pkId = request.getParameter("key"); 
			mobileMessageVO = mobileMessageService.getById(pkId);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			e.printStackTrace();
		}
		return SUCCESS;

	}

	public MobileMessageVO getMobileMessageVO() {
		return mobileMessageVO;
	}

	public void setMobileMessageVO(MobileMessageVO mobileMessageVO) {
		this.mobileMessageVO = mobileMessageVO;
	}

	public void setMobileMessageService(IMobileMessageService mobileMessageService) {
		this.mobileMessageService = mobileMessageService;
	}

	public List<MobileMessageVO> getMobileMessageList() {
		return mobileMessageList;
	}

	public void setMobileMessageList(List<MobileMessageVO> mobileMessageList) {
		this.mobileMessageList = mobileMessageList;
	}

}